import React, { Component } from 'react'
import './index.css'
export default class Footer extends Component {
  //全选事件处理函数
  handleCheaclAll = (e) => {
    this.props.checkAllTode(e.target.checked)
  }
  //清除已完成的事件处理函数
  handleClearAllDone=()=>{
      this.props.clearAllDone()
  }


  render() {
    const { todos } = this.props
    //计算已完成的数量
    const doneCount = todos.reduce((pre, current) => {
      return pre + (current.done ? 1 : 0)
    }, 0)
    //总数
    const total = todos.length
    return (
      <div className="todo-footer">
        <label>
          <input type="checkbox" onChange={this.handleCheaclAll} checked={doneCount === total && total !== 0 ? true : false} />
        </label>
        <span>
          <span>已完成{doneCount}</span> / 全部{total}
        </span>
        <button className="btn btn-danger" onClick={this.handleClearAllDone}>清除已完成任务</button>
      </div>
    )
  }
}
